/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__trim_parenthesis.c                             */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/15 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"

#include "../../../../src/module/oracle/config.h"
#include <oracle/ora_core.h>
#include <oracle/comm/ora_comm.h>

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

void __trim_parenthesis(char **pp_data);

static void __case1(void)
{
    char **pp_buffer;

    pp_buffer = NULL;

    __trim_parenthesis(pp_buffer);
}

static void __case2(void)
{
    char *p_buffer = NULL;

    __trim_parenthesis(&p_buffer);
}

static void __case3(void)
{
    char *p_buffer = NULL;
    char *p_test = NULL;

    p_buffer = (char *) frmalloc(strlen("(DESCRIPTION)") + 1);
    snprintf(p_buffer, strlen("(DESCRIPTION)") + 1, "%s", "(DESCRIPTION)");

    p_test = p_buffer;

    __trim_parenthesis(&p_buffer);

    CU_ASSERT_STRING_EQUAL(p_buffer, "DESCRIPTION");
    frfree(p_test);
}

static void __case4(void)
{
    char *p_buffer = NULL;
    char *p_test = NULL;

    p_buffer = (char *) frmalloc(strlen("DE(SCRIPTI)ON") + 1);
    snprintf(p_buffer, strlen("DE(SCRIPTI)ON") + 1, "%s", "DE(SCRIPTI)ON");

    p_test = p_buffer;

    __trim_parenthesis(&p_buffer);

    CU_ASSERT_STRING_EQUAL(p_buffer, "DE(SCRIPTI)ON");
    frfree(p_test);
}

int add_suite__trim_parenthesis(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __trim_parenthesis()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
